SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

/****** 
 Object: User Defined Function dbo.fnStripTags
 Script Author: Robert Davis, robertd@realtechllc.com 
 Purpose: Strip HTML tags out of text. Anything enclosed in '<' and '>' will be removed.
******/
ALTER  Function dbo.fnStripTags
	(@Dirty varchar(4000))
	Returns varchar(4000)
As
Begin
	Declare @Start int,
		@End int,
		@Length int
	While CharIndex('<', @Dirty) > 0 And CharIndex('>', @Dirty, CharIndex('<', @Dirty)) > 0
	    Begin
		Select @Start = CharIndex('<', @Dirty), 
		  @End = CharIndex('>', @Dirty, CharIndex('<', @Dirty))
		Select @Length = (@End - @Start) + 1
		If @Length > 0
		    Begin
			Select @Dirty = Stuff(@Dirty, @Start, @Length, '')
		    End
	    End
	return @Dirty
End

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

